package io.easyspring.invitation.core;

import io.easyspring.invitation.core.impl.EasyInvitationProcessor;
import io.easyspring.invitation.core.impl.RedisInvitationRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 邀请信息的 Bean 的配置类
 *
 * @author summer
 * @version 2.0.0-RELEASE
 * DateTime 2019-06-22 14:32
 */
@Configuration
public class InvitationBeanConfig {

    /**
     * 邀请信息存储器
     *
     * @return io.easyspring.invitation.core.InvitationRepository
     * Author summer
     * Version 2.0.0-RELEASE
     * DateTime 2019-06-22 14:35
     */
    @Bean
    @ConditionalOnMissingBean(InvitationRepository.class)
    public InvitationRepository invitationRepository(){
        // 默认创建 Redis 的存储器
        return new RedisInvitationRepository();
    }

    /**
     * 邀请信息的处理器
     *
     * @return io.easyspring.invitation.core.InvitationProcessor
     * Author summer
     * Version 2.0.0-RELEASE
     * DateTime 2019-06-22 14:36
     */
    @Bean
    @ConditionalOnMissingBean(InvitationProcessor.class)
    public InvitationProcessor invitationProcessor(){
        // 返回默认的短信生成器
        return new EasyInvitationProcessor();
    }
}
